<template>
  <transition name="loading-fade" appear>
    <div v-if="show" class="loader-wrapper">
      <div class="loader">
        <img src="@/assets/developer.png" alt="WeBlog Logo" />  
      </div>
    
      <div class="loader-text">
        <div>欢</div>
        <div>迎</div>
        <div>光</div>
        <div>临</div>
        <div>A</div>
        <div>I</div>
        <div>R</div>
        <div>S</div>
        <div>的</div>
        <div>blog</div>
      </div>
      <div class="enter-hint" @click="enterMainPage">
        <div class="hint-text">点击进入blog</div>
        <div class="arrow-down">
          <svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
            <path d="M7 13L12 18L17 13" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
          </svg>
        </div>
      </div>
    </div>
  </transition>
</template>

<script setup>
const props = defineProps({
  show: {
    type: Boolean,
    default: true
  }
})

// 由用户点击触发进入主页面
const enterMainPage = () => {
  if (typeof window !== 'undefined') {
    window.dispatchEvent(new CustomEvent('loadingComplete'))
  }
}
</script>

<style scoped>
* {
  /* 初始化 */
  margin: 0;
  padding: 0;
}

body {
  /* 100%窗口高度 */
  height: 100vh;
}

.loader-wrapper {
  /* 固定定位 */
  position: fixed;
  left: 0;
  top: 0;
  z-index: 9999;
  width: 100%;
  height: 100%;
  /* 溢出隐藏 */
  overflow: hidden;
  /* 渐变背景 */
  background-image: url('https://java-file-spring.oss-cn-beijing.aliyuncs.com/Loding.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

/* 头像容器 */
.loader {
  width: 300px;
  height: 300px;
  /* 相对定位 居中 */
  position: relative;
  left: 50%;
  top: 38%;
  margin-left: -150px;
  margin-top: -150px;
  z-index: 2;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  /* 添加头像容器的背景效果 */
  animation: float 3s ease-in-out infinite;
}

/* logo */
.loader img {
  width: 90%;
  height: 90%;
  border-radius: 50%;
  /* 添加头像边框 */
  border: 3px solid rgba(255, 255, 255, 0.8);
  /* 添加头像阴影 */
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.15);
}

.loader-text {
  width: 50%;
  height: 36px;
  /* 绝对定位 水平居中 */
  position: absolute;
  top: 72%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  /* 防止选取 */
  user-select: none;
}

.loader-text div {
  width: 30px;
  height: 36px;
  color: #fff;
  font-size: 32px;
  margin: 0 20px;
  /* 绝对定位 */
  position: absolute;
  /* 默认隐藏+旋转180度 */
  opacity: 0;
  transform: rotate(180deg);
  /* 执行文字移动动画 */
  animation: move 2s linear infinite;
}

/* 最后面的三个圆 */
.loader-text div:nth-child(8)::before,
.loader-text div:nth-child(9)::before,
.loader-text div:nth-child(10)::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: #fff;
  position: absolute;
  left: 0;
  bottom: 0;
}

/* 文字下的投影 */
.loader-text div::after {
  content: "";
  width: 10px;
  height: 5px;
  border-radius: 50%;
  background-color: rgba(255,255,255,0.15);
  position: absolute;
  bottom: -40px;
  left: 50%;
  margin-left: -5px;
}

/* 最后面的三个圆的投影 */
.loader-text div:nth-child(8)::after,
.loader-text div:nth-child(9)::after,
.loader-text div:nth-child(10)::after {
  left: 0;
  margin-left: 0;
}

/* 接下来为各个文字设置动画延迟时间 */
.loader-text div:nth-child(2) {
  animation-delay: 0.2s;
}

.loader-text div:nth-child(3) {
  animation-delay: 0.4s;
}

.loader-text div:nth-child(4) {
  animation-delay: 0.6s;
}

.loader-text div:nth-child(5) {
  animation-delay: 0.8s;
}

.loader-text div:nth-child(6) {
  animation-delay: 1s;
}

.loader-text div:nth-child(7) {
  animation-delay: 1.2s;
}

.loader-text div:nth-child(8) {
  animation-delay: 1.4s;
}

.loader-text div:nth-child(9) {
  animation-delay: 1.6s;
}

.loader-text div:nth-child(10) {
  animation-delay: 1.8s;
}

/* 进入主页面提示 */
.enter-hint {
  position: absolute;
  bottom: 10%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  /* 防止选取 */
  user-select: none;
  animation: fadeIn 1.5s ease-in-out;
  /* 鼠标样式改为指针，表示可点击 */
  cursor: pointer;
  /* 添加悬停效果 */
  transition: transform 0.3s ease;
}

.enter-hint:hover {
  transform: translateX(-50%) translateY(-5px);
}

.hint-text {
  color: #fff;
  font-size: 18px;
  font-weight: 600;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  /* 执行呼吸动画 */
  animation: breath 2s ease-in-out infinite;
}

.arrow-down {
  width: 30px;
  height: 30px;
  /* 执行上下浮动动画 */
  animation: floatUpDown 2s ease-in-out infinite;
}

.arrow-down svg {
  width: 100%;
  height: 100%;
}

/* 定义动画 */
/* 背景渐变动画 */
@keyframes gradient {
  50% {
    background-position: 100% 0%;
  }
}

/* 旋转动画 */
@keyframes spin {
  0% {
    transform: rotate(0);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* 文字移动动画 */
@keyframes move {
  0% {
    right: 0;
    opacity: 0;
  }
  35% {
    right: 41%;
    opacity: 1;
    transform: rotate(0);
  }
  65% {
    right: 59%;
    opacity: 1;
    transform: rotate(0);
  }
  100% {
    right: 100%;
    transform: rotate(-180deg);
  }
}

/* 淡入动画 */
@keyframes fadeIn {
  0% {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
  100% {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* 呼吸动画 */
@keyframes breath {
  0%, 100% {
    opacity: 0.7;
  }
  50% {
    opacity: 1;
  }
}

/* 上下浮动动画 */
@keyframes floatUpDown {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}

/* 头像浮动动画 */
@keyframes float {
  0%, 100% {
    transform: translateY(0) scale(1);
  }
  50% {
    transform: translateY(-10px) scale(1.05);
  }
}

/* 过渡动画 */
.loading-fade-enter-active,
.loading-fade-leave-active {
  transition: opacity 0.5s ease;
}

.loading-fade-enter-from,
.loading-fade-leave-to {
  opacity: 0;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .loader {
    width: 120px;
    height: 120px;
    margin-left: -60px;
    margin-top: -60px;
  }
  
  .loader-text {
    width: 80%;
  }
  
  .loader-text div {
    width: 24px;
    height: 30px;
    font-size: 26px;
    margin: 0 15px;
  }
  
  .hint-text {
    font-size: 16px;
  }
  
  .arrow-down {
    width: 25px;
    height: 25px;
  }
}
</style>